package business.database.maauco;

import business.coding.CandidateCenter;
import business.database.filtersemantic.CorpsFilterSQLGen;
import domain.Center
import groovy.lang.Closure;
import groovy.sql.Sql
import java.util.List;
import org.apache.log4j.Logger;

/**
 * Acceso a la tabla AUPIO
 * @author 53385255R
 *
 */
public class AUPIODAO {

	private Sql sqlAUPIO;
	private Logger log;
	
	/**
	* Constructor con la conexion
	* @param sql
	*/
	public AUPIODAO(Sql sql) {
		sqlAUPIO = sql;
		log = Logger.getLogger("AUPIODAO");
	}
	
	/**
	 * Elimina en el IDNO en AUPIO
	 * @param idno
	 */
	public void delete(Integer idno) {

		sqlAUPIO.execute("delete * from AUPIO where idno = ${idno}");
		
	}
	
		
	public void addNew(RegAupio reg){
		String sql="INSERT INTO AUPIO (IDNO, [NO], NUMADD) values(${reg.idno},${reg.no},${reg.numadd})"
		sqlAUPIO.execute(sql);
	}
	
	
	public List <RegAupio> getReg(Integer idno){
		
		List<RegAupio> regs = new ArrayList<RegAupio>();
				
		String sql="SELECT AUPIO.IDNO, AUPIO.[NO],AUPIO.NUMADD From AUPIO WHERE AUPIO.IDNO=${idno};"
		
		sqlAUPIO.eachRow(sql) {
			Integer IDNO=it[0]
			Integer no=it[1]
			Integer numadd=it[2]
			RegAupio reg= new RegAupio(idno, no, numadd)
			regs.add(reg);
		}
		return regs;
	}
}
